// 基于准备好的dom，初始化echarts实例
var myChart1 = echarts.init(document.getElementById('website-visit24'), 'light');
var myChart2 = echarts.init(document.getElementById('website-visit'), 'light');
var myChart3 = echarts.init(document.getElementById('article-visit'), 'light');
var myChart4 = echarts.init(document.getElementById('comment-count'), 'light');

// 指定图表的配置项和数据

// 24小时
var option1 = {
	title: {},
	tooltip: {},
	legend: {
		data: ['每小时', '总计'],
		selected: {
			"每小时": true,
			"总计": false
		}
	},
	xAxis: {
		data: ["00:00", "02:00", "04:00", "06:00", "08:00", "10:00", "12:00",
			"14:00", "16:00", "18:00", "20:00", "22:00"
		]
	},
	yAxis: {
		// data: ["0", "20", "40", "60", "80", "100"]
		type: "value",
	},
	series: [{
		name: '每小时',
		type: 'line',
		data: [5, 20, 36, 10, 10, 80, 115, 120, 136, 140, 180, 190],
	}, {
		name: '总计',
		type: 'line',
		data: [5, 25, 65, 76, 86, 97, 135, 160, 186, 190, 200, 620],
	}],
};

// 总网站统计
var option2 = {
	title: {},
	tooltip: {},
	legend: {
		data: ['每小时', '总计'],
		selected: {
			"每天": true,
			"总计": false
		}
	},
	xAxis: {
		data: ["01/01", "02/01", "01/01", "02/01", "01/01", "02/01", "01/01", "02/01"]
	},
	yAxis: {
		// data: ["0", "20", "40", "60", "80", "100"]
		type: "value",
	},
	series: [{
		name: '每小时',
		type: 'line',
		color: ['#009688'],
		data: [5, 20, 36, 10, 10, 80, 115, 120, 136, 140, 180, 190],
	}, {
		name: '总计',
		type: 'line',
		data: [5, 25, 65, 76, 86, 97, 135, 160, 186, 190, 200, 620],
	}],
};

// 文章访问量
var option3 = {
	title: {},
	tooltip: {},
	legend: {
		data: ['每小时', '总计'],
		selected: {
			"每小时": true,
			"总计": false
		}
	},
	xAxis: {
		data: ["00:00", "02:00", "04:00", "06:00", "08:00", "10:00", "12:00",
			"14:00", "16:00", "18:00", "20:00", "22:00"
		]
	},
	yAxis: {
		// data: ["0", "20", "40", "60", "80", "100"]
		type: "value",
	},
	series: [{
		name: '每小时',
		type: 'line',
		color: ['#FFB800'],
		data: [15, 120, 316, 101, 120, 210, 115, 120, 136, 140, 180, 190],
	}, {
		name: '总计',
		type: 'line',
		data: [5, 25, 65, 76, 86, 97, 135, 160, 186, 190, 200, 620],
	}],
};

// 文章评论数
var option4 = {
	title: {},
	tooltip: {},
	legend: {
		data: ['每小时', '总计'],
		selected: {
			"每小时": true,
			"总计": false
		}
	},
	xAxis: {
		data: ["00:00", "02:00", "04:00", "06:00", "08:00", "10:00", "12:00",
			"14:00", "16:00", "18:00", "20:00", "22:00"
		]
	},
	yAxis: {
		// data: ["0", "20", "40", "60", "80", "100"]
		type: "value",
	},
	series: [{
		name: '每小时',
		type: 'line',
		color: ['#FF5722'],
		data: [52, 202, 326, 120, 210, 280, 112, 120, 126, 120, 180, 290],
	}, {
		name: '总计',
		type: 'line',
		data: [5, 25, 65, 76, 86, 97, 135, 160, 186, 190, 200, 620],
	}],
};

myChart1.setOption(option1);
myChart2.setOption(option2);
myChart3.setOption(option3);
myChart4.setOption(option4);

// document.getElementsByClassName("item-btn")[0].onclick = function() {
// 	var i = 0;
// 	var timer = setInterval(function(){
// 		myChart.resize();
// 		console.log("执行", i);
// 		i++;
// 			if(i>80) {clearInterval(timer); i = 0;console.log("执行if")}
// 	}, 30);

// }

function resizeChart(n) {
	var i = 0;
	var timer = setInterval(function() {
		switch (n) {
			case 1:
				myChart1.resize();
				chartBtnTemp = 1;
				break;
			case 2:
				myChart2.resize();
				chartBtnTemp = 2;
				break;
			case 3:
				myChart3.resize();
				chartBtnTemp = 3;
				break;
			case 4:
				myChart4.resize();
				chartBtnTemp = 4;
				break;
			default:
				myChart1.resize();
				chartBtnTemp = 1;
		}
		console.log("执行", i);
		i++;
		if (i > 60) {
			clearInterval(timer);
			i = 0;
			console.log("执行if")
		}
	}, 30);
}
